<script setup>
import { onMounted, onUnmounted } from "vue";
import router from "@/router/index";
import { _$, $, to } from "./index";

onMounted(() => {
  $.onSearch();
});

onUnmounted(() => {
  $.clean();
});
</script>

<template>
  <el-space direction="vertical" fill wrap class="w-fill" :size="20">
    <el-page-header @back="router.back()" size="small">
      <template #content>
        <span class="text-large font-600 mr-3">用户信息</span>
      </template>
    </el-page-header>
    <el-card class="w-fill" shadow="never">
      <el-form
        label-width="auto"
        :inline="true"
        :model="_$.query.requestParam"
        size="small"
        class="demo-form-inline"
      >
        <el-form-item label="用户名">
          <el-input v-model="_$.query.requestParam.condition" clearable />
        </el-form-item>
        <el-form-item>
          <el-space wrap>
            <el-button @click="$.onReset">重置</el-button>
            <el-button type="primary" @click="$.onSearch">查询</el-button>
          </el-space>
        </el-form-item>
      </el-form>
    </el-card>
    <el-card class="w-fill" shadow="never">
      <el-space direction="vertical" fill wrap class="w-fill" :size="20">
        <div style="display: flex; align-items: center">
          <el-space wrap :size="10">
            <el-button
                type="primary"
                size="small"
                @click="router.push('/manage/user/normal/edit')"
            >新增</el-button>
              <el-tooltip content="请先选择需要删除的数据" placement="right">
                <el-button
                    type="warning"
                    size="small"
                    @click="$.onDelete"
                    :disabled="_$.delete.requestParam.ids.length === 0"
                >删除</el-button
                >
              </el-tooltip>

          </el-space>
        </div>
        <el-table
          :data="_$.query.responseParam.records"
          size="small"
          stripe
          style="width: 100%; height: 500px"
          @selection-change="$.handleSelectionChange"
        >
          <el-table-column type="selection" width="55" />
          <el-table-column type="index" label="序号" width="60" />
          <el-table-column label="操作" width="60">
            <template #default="scope">
              <el-button
                  icon="edit"
                  size="small"
                  link
                  @click="$router.push('/manage/user/normal/edit?id=' + scope.row.id)"
              />
            </template>
          </el-table-column>
          <el-table-column type="expand">
            <template #default="props">
              <div>
                <el-descriptions :column="3" size="small" border>
                  <el-descriptions-item label="用户名" width="80px">{{
                    props.row.username
                  }}</el-descriptions-item>
                  <el-descriptions-item label="昵称" width="80px">{{
                    props.row.name
                  }}</el-descriptions-item>
                  <el-descriptions-item label="性别" width="80px">
                    <el-text v-if="props.row.gender == '1'"> 男 </el-text>
                    <el-text v-else> 女 </el-text>
                  </el-descriptions-item>
                  <el-descriptions-item label="手机号" width="80px">
                    {{ props.row.phone }}
                  </el-descriptions-item>
                  <el-descriptions-item label="邮箱" width="80px">
                    {{ props.row.email }}
                  </el-descriptions-item>
                </el-descriptions>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="username" label="用户名">
            <template #default="scope">
              <el-button
                type="primary"
                link
                @click="to.goToDetail(scope.row.id)"
              >
                {{ scope.row.username }}
              </el-button>
            </template>
          </el-table-column>
          <el-table-column prop="name" label="昵称" />
          <el-table-column prop="phone" label="手机号" />
          <el-table-column prop="cdate" label="创建时间" align="center" />
          <el-table-column prop="edate" label="更新时间" align="center" />
        </el-table>
        <div style="display: flex">
          <div class="flex-grow" />
          <el-pagination
            v-model:current-page="_$.query.requestParam.pageNum"
            v-model:page-size="_$.query.requestParam.pageSize"
            :page-sizes="[20, 50, 100, 200]"
            :small="true"
            layout="total, sizes, prev, pager, next, jumper"
            :total="_$.query.responseParam.total"
            @size-change="$.handleSizeChange"
            @current-change="$.handleCurrentChange"
          />
        </div>
      </el-space>
    </el-card>
  </el-space>
</template>

<style scoped></style>
